Get Elements Values Using Function with Local Variables

pragma encoding, "UTF-8"
pragma runLim, 0
 
void saveData(DB win){
     //Here I need to get the element(Number) from the current window(Window), is this possible?
     string s = get(win,Number)
     print s"\n"
}
 
void closeWin(DB win){
    hide(win)
        destroy(win)
}
 
// This function shows the new SVN window
void initWindow(){
        DB Window = null
        DBE Number = null
        DBE Location = null
        //Object thisObj = current(crMod)
        Window = centered("Number - Location - Data")
        
        Number = text(Window, "Number:", "",100, 20,false)
        Number ->"right" -> "unattached"
        Number ->"top"->"form"
        
        Location = text(Window, "Location:", "",500, 20,false)
        Location ->"left" -> "spaced"->Number 
        Location ->"top" -> "aligned"->Number
        Location ->"top"->"form"
        
        apply(Window, "Save", saveData)
        close(Window,true, closeWin)
        realize Window
}
initWindow()

 


Hi,
Is it possible to get a value of an element from a dialog box
Example:
1. get(DB win).(DBE Elem) //Sort of like getting user properties
2. like getTitle(DB win)

I really need this, but without the need of having to set the variable global.

 


SystemAdmin - Thu Nov 11 13:25:44 EST 2010

Re: Get Elements Values Using Function with Local Variables
llandale - Thu Nov 11 15:24:18 EST 2010

You should routinely declare your DB and DBE variables near the top of your code in the main context. This allows your various callback functions the ability to deal with them.

pragma encoding, "UTF-8"
pragma runLim, 0
 
DB  Window   = null         // Routinely declare DB and DBEs at the top in the main code
DBE Number   = null
DBE Location = null
 
void saveData(DB win){
     //Here I need to get the element(Number) from the current window(Window), is this possible?
     string s = get(Number)    // <<==Get the Number from the DBE
     print s "\n"
}
 
void closeWin(DB win){
    hide(win)
        destroy(win) 
}
 
// This function shows the new SVN window
void initWindow(){
        //Object thisObj = current(crMod)
        Window = centered("Number - Location - Data")
        
        Number = text(Window, "Number:", "",100, 20,false)
        Number ->"right"  -> "unattached"
        Number ->"top"    ->"form"
        
        Location = text(Window, "Location:", "",500, 20,false)
        Location ->"left" -> "spaced"->Number 
        Location ->"top"  -> "aligned"->Number
        Location ->"top"  ->"form"
        
        apply(Window, "Save", saveData)
        close(Window,true, closeWin)
        realize Window
}
initWindow()


Someone else once showed code that allowed for non-global declarations of DB and DBEs by storing them clevery in a (global) skip, but that seemed like excessive FCS (Fancy Code Syndrome) for routine scripts with a single dialog (like this one).

Nit Picks:
o Your 'location' has two 'top' placements; the 1st one is ignored. And that's good since it turns out attempting to align the 'top' of the 'text' often doesn't work, for reasons only Martians understand.
o I suspect your stiff 'realize' is inadequate, you should 'show' your dialog afterwards. I don't recall the exact rules, but 'realized' but not 'shown' dialogs prevent many kinds of interaction. It may be, however, that since your code ends after the realize, that a 'show' isn't needed. Never actually done that.
o Avoid 'Window' as a variable name, I believe its also a data type and things can get confused.
o Your closeWin() works, but only because there is nothing else going on. Instead it should deal directly with "Window", hiding and destroying it and setting it to null.
o I routinely declare ALL my DBs and DBEs with "db" and "dbe" respectively, perhaps you could do this to make the rest of the code easier to grasp.
DB dbWindow = null
DBE dbeNumber = null
DBE dbeLocation = null

 

 

  • Louie